package com.orange.adminapi.controller.venue;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.pojo.BR;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.venue.dto.VenueDTO;
import com.orange.core.pojo.entity.venue.vo.VenueVO;
import com.orange.core.pojo.req.venue.VenuePageReq;
import com.orange.core.service.venue.VenueService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>ClassName:VenueController</p>
 * <p>Description: 场地管理</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/5/22 0:17</p>
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/venue")
public class VenueController {

    private final VenueService venueService;

    /**
     * 场地分页查询
     *
     * @param pageReqDto
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).VENUE_LIST.permission.identifier)")
    @PostMapping("/page")
    public R<Page<VenueVO>> page(@RequestBody PageReqDto<VenuePageReq> pageReqDto){
        Page<VenueVO> page = venueService.page(pageReqDto);
        return R.ok(page);
    }

    /**
     * 场地详情
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).VENUE_INFO.permission.identifier)")
    @GetMapping("/info/{id}")
    public R<VenueVO> info(@PathVariable("id") int id){
        return R.ok(venueService.info(id));
    }

    /**
     * 场地新增
     * @param venueDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).VENUE_SAVE.permission.identifier)")
    @PostMapping
    public R<Boolean> save(@RequestBody @Validated VenueDTO venueDTO){
        return BR.result(venueService.save(venueDTO));
    }

    /**
     * 场地修改
     * @param venueDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).VENUE_UPDATE.permission.identifier)")
    @PutMapping
    public R<Boolean> update(@RequestBody @Validated VenueDTO venueDTO){
        return BR.result(venueService.update(venueDTO));
    }


    /**
     * 场地删除
     * @param ids
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).VENUE_DELETE.permission.identifier)")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable("ids") Integer[] ids){
        Boolean result = venueService.deleteVenueByIds(ids);
        return BR.result(result);
    }

}
